package artid.com.arttogo.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.NewartListParser;
import artid.com.arttogo.utils.NetUtils;
import artid.com.arttogo.view.DynamicHeightImageView;

/**
 * 
 *    
 * 项目名称：ArtworkArt   
 * 类名称：ArtistWorksPicture_Adapter   
 * 类描述：艺术家个人作品图适配器   
 * 创建人：耿卫斌   
 * 创建时间：2017-1-5 下午4:07:32   
 *
 */
@SuppressLint("NewApi") public class ArtistWorksPicture_Adapter extends BaseAdapter {
	private Context mContext;
	private List<NewartListParser> list;

	public ArtistWorksPicture_Adapter(Context mContext,
									  List<NewartListParser> list) {
		super();
		this.mContext = mContext;
		this.list = list;
	}

	public void notifyData(List<NewartListParser> list) {
		// TODO Auto-generated method stub
		this.list = list;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		View v = convertView;
		if (v == null) {
			holder = new ViewHolder();
			v = LayoutInflater.from(mContext).inflate(R.layout.item_staggeredgrid, null);
			holder.img=(DynamicHeightImageView) v.findViewById(R.id.item_staggeredgrid_img);
			holder.describe=(TextView) v.findViewById(R.id.item_staggeredgrid_describe);
			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}
		//这里图片高度高于手机屏幕之后就采用自适应，要不然会有BUG
		if(list.get(position).getImghight()< Integer.parseInt(NetUtils.getDisplayMetrics((Activity)mContext).get(NetUtils.DM_HEIGHT))){
			holder.img.setHeight(list.get(position).getImghight());
		}
		ImageLoader.getInstance().displayImage(list.get(position).getArtimag()
				+ "_"+ (Integer.parseInt(NetUtils.getDisplayMetrics((Activity)mContext).get(NetUtils.DM_WIDTH)) /2) + "x10.png", holder.img);
		holder.describe.setText(list.get(position).getArtname());
		return v;
	}
	class ViewHolder {
		DynamicHeightImageView img;
		TextView describe;
	}


}